﻿using IDAL;
using Microsoft.EntityFrameworkCore;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace DAL
{
   public  class OutcallDAL:IOutCallDAL
    {
        /// <summary>
        /// 获取出诊列表
        /// </summary>
        /// <returns></returns>
        public List<ShowOutcallview> GetOutcalls()
        {
            using (MyDBContext db = new MyDBContext())
            {
                
                var list = (from o in db.Outcall
                            join p in db.Patient on o.Patient_Id equals p.Patient_Id
                            join d in db.Doctor on o.Doctor_Id equals d.Doctor_Id
                            join t in db.Outpatient on o.Outpatient_Id equals t.Outpatient_Id
                            select new ShowOutcallview
                            {
                                Outcalls_Id = o.Outcalls_Id,
                                Outcalls_number = o.Outcalls_number,
                                Patient_Num = p.Patient_Num,
                                Registration = o.Registration,
                                Doctor_Name = d.Doctor_Name,
                                Outpatient_Name = t.Outpatient_Name,
                                Outcalls_State = o.Outcalls_State
                            }).ToList();
                return list;
            }
        }

        /// <summary>
        /// 出诊详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Outcalls GetOutcallsById(int id)
        {
            using (MyDBContext db = new MyDBContext())
            {
                return db.Outcall.Where(e => e.Outcalls_Id == id).FirstOrDefault();
            }
        }
    }
}
